// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class EXPERIENCE_PEX_P08 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("19 PES",19)]
  	    [HL7Field(HL7Version.v23, 19, HL7Repeat.False, HL7Required.True,"PES")]
	    public PES PES {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("20 PEX_OBSERVATION",20)]
  	    [HL7Field(HL7Version.v23, 20, HL7Repeat.True, HL7Required.True,"PEX_OBSERVATION_PEX_P08")]
	    public PEX_OBSERVATION_PEX_P08[] PEX_OBSERVATION {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("84 STUDY",84)]
  	    [HL7Field(HL7Version.v23, 84, HL7Repeat.False, HL7Required.False,"STUDY_PEX_P08")]
	    public STUDY_PEX_P08 STUDY {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			PES = PopSegmentParseAndCheckRequired<PES>(availableData, options, "PES");
			PEX_OBSERVATION = ProcessGroupArray<PEX_OBSERVATION_PEX_P08>(availableData, options, "PEX_OBSERVATION");
			STUDY = ProcessGroup<STUDY_PEX_P08>(availableData, options, "STUDY");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isPES = availableData.StartsWith("PES", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PES", options.Version) || isPES) {
				return isPES;
			}
			PEX_OBSERVATION_PEX_P08 testPEX_OBSERVATION_PEX_P08 = new PEX_OBSERVATION_PEX_P08();
			bool grpCCPEX_OBSERVATION_PEX_P08 = (testPEX_OBSERVATION_PEX_P08.CanConsume(availableData, options));
			if (IsRequired("PEX_OBSERVATION", options.Version) || grpCCPEX_OBSERVATION_PEX_P08) {
				return grpCCPEX_OBSERVATION_PEX_P08;
			}
			STUDY_PEX_P08 testSTUDY_PEX_P08 = new STUDY_PEX_P08();
			bool grpCCSTUDY_PEX_P08 = (testSTUDY_PEX_P08.CanConsume(availableData, options));
			if (IsRequired("STUDY", options.Version) || grpCCSTUDY_PEX_P08) {
				return grpCCSTUDY_PEX_P08;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "EXPERIENCE";
			}
        }

        static EXPERIENCE_PEX_P08() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(EXPERIENCE_PEX_P08));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (PES != null) {
			string segmentValue = PES.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (PEX_OBSERVATION != null && PEX_OBSERVATION.Length > 0) {
			for (int i = 0; i < PEX_OBSERVATION.Length; i++) {
				string segmentValue = PEX_OBSERVATION[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (STUDY != null) {
			string segmentValue = STUDY.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

